#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include"handler.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->sc=new scene;
    this->ui->graphicsView->setScene(sc);
    connect(this->ui->start,SIGNAL(clicked(bool)),this->sc,SLOT(startGame()));   //开始按钮
    connect(this->ui->pause,SIGNAL(clicked(bool)),this->sc,SLOT(pauseGame()));   //暂停按钮
    connect(this->ui->stop,SIGNAL(clicked(bool)),this->sc,SLOT(stopGame()));   //结束按钮
    this->score=0;  //初始化得分
    handler*hand=handler::getInstance();
    connect(hand,SIGNAL(beat()),this,SLOT(addScore()));    //接收信号，绑定得分槽函数
}
MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::closeEvent(QCloseEvent *event)    //实现关闭程序的函数
{
    int ret= QMessageBox::question(this,"确定","你真的要关闭吗？","Yes","No");
    //judge 是否关闭
    if(ret==1){
        event->ignore();
    }
}
void MainWindow::addScore(){
    this->score+=1;
    this->ui->lcdNumber->display(this->score);
}
